package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fs.mapper.Inventory;
import com.fs.mapper.InventoryDetail;
import com.fs.pojo.WhInvInventory;
import com.fs.pojo.WhInvInventoryDetail;
import com.fs.service.InventoryDetailService;
import com.fs.service.InventoryService;
import com.fs.vo.Condition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yyds
 * @fileName InventoryServiceImpl
 * @date 2024/10/11 14:33
 * @description
 **/
@Service
public class InventoryServiceImpl implements InventoryService {
    @Resource
    private Inventory inventory;
    @Resource
    private InventoryDetailService inventoryDetailService;

    /**
     * 分页查询盘点单
     *
     * @param condition
     * @return date
     */
    @Override
    public PageInfo<WhInvInventory> selectAll(Condition<WhInvInventory> condition) {
        PageHelper.startPage(condition.getPage(), condition.getCount());
        List<WhInvInventory> whInvInventories = inventory.selectAll(condition.getSearch());
        return new PageInfo<>(whInvInventories);
    }

    /**
     * 新增盘点单
     *
     * @param condition
     * @return yes/no
     */
    @Override
    public Boolean addInventory(Condition<WhInvInventory> condition) {
        return inventory.insert(condition.getSearch()) > 0;
    }

    /**
     * 根据编号删除盘点单
     *
     * @param id
     * @return yes/no
     */
    @Transactional
    @Override
    public Boolean deleteInventory(Integer id) {
        return inventory.deleteById(id) > 0 && inventoryDetailService.deleteDetailByInventory(id);
    }

    /**
     * 根据编号修改盘点单
     *
     * @param condition
     * @return
     */

    @Override
    public Boolean updateInventory(Condition<WhInvInventory> condition) {
        return inventory.updateById(condition.getSearch()) > 0;
    }

    /**
     * 查询最大id
     * @return
     */
    @Override
    public Integer maxID() {
        return inventory.maxID()+1;
    }
    /**
     * 根据ID获取对象
     * @param id
     * @return
     */
    @Override
    public WhInvInventory selectById(Integer id) {
        return inventory.selectById(id);
    }

}
